// pages/order/list/list.js
// import Vue from 'vue';
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    resultList:[],
    sign: true
  },
  getRecordList: function(even){
    var that = this
    let status = ""
    var canteen_id = wx.getStorageSync('canteen_id')
    var window_id = wx.getStorageSync('window_id')
    if(canteen_id != null && window_id != null){
      if(even != null){
        status = even.currentTarget.dataset.status;
      }
      console.log(status)
       wx.cloud.callFunction({
        name: 'record_findAllorder',
        data: {
          status:status,
          canteen_id:canteen_id,
          window_id:window_id
        }
      }).then(function(res){
        console.log(res)
        that.setData({
          resultList:res.result,
          sign:!that.data.sign
        })
      })
    }else{
      wx.showToast({
        title: '请先填写信息',
        icon: 'none',
        duration: 2000
      }),
      setTimeout(function () {
        wx.navigateTo({
          url: '/pages/root/login/login',
        })
      },2000)
    }
   
  },
  getRecord: function(even){
    const that = this;
    let status = "";
    status = even.currentTarget.dataset.status
    if(that.data.sign == true && status == '0'){
      return;
    }
    if(that.data.sign == false && status == ''){
      return;
    }
    this.getRecordList(even)
  },
  btn: function(event){ 
    const that = this;
    let message = "你确定将该套餐修改为已取餐吗？"
    if( "2" == event.detail.type){
      message = "你确定将该套餐修改为未取餐吗？"
    }
    Dialog.confirm({
      title: '更新状态',
      message:message,
    })
      .then(() => {
        let id = event.detail.id
        let type = event.detail.type
        wx.cloud.callFunction({
          name: 'record_updateStatus',
          data: {
            id:id,
            type: type
          }
        }).then(function(res){
          that.getRecordList({
            currentTarget:{
              dataset:{
                status:"0"
              }
            }
          })
          that.setData({
            sign:!that.data.sign
          })
        })
      })
      .catch(() => {
      });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRecordList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})